package com.achilles.learnresultreceiver;

import android.app.IntentService;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.ResultReceiver;
import android.util.Log;

public class CalcService extends IntentService {

    public static final int RESULTCODE_BEGIN = 0;
    public static final int RESULTCODE_END = 1;

    public CalcService() {
        super("com.achilles.learnresultreceiver.calcservice");
        Log.i("AchillesL","onCreate");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        ResultReceiver resultReceiver = intent.getParcelableExtra("resultReceiver");
        resultReceiver.send(RESULTCODE_BEGIN,null);

        Log.d("AchillesL","CalService " + Thread.currentThread().getName());

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        resultReceiver.send(RESULTCODE_END,null);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("AchillesL","onDestroy");
    }
}
